package com.fr.base.core;

import com.fr.base.DefaultValues;
import com.fr.base.FRContext;
import com.fr.base.FRFont;
import com.fr.base.StringUtils;
import com.fr.base.Style;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.Toolkit;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.LineMetrics;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Dimension2D;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.text.AttributedString;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.JLabel;

public class GraphHelper
{
  private static Line2D tmpLine2D = new Line2D.Double(0.0D, 0.0D, 0.0D, 0.0D);
  private static Font oldFont = null;
  private static FontMetrics oldFontMetrics = null;
  private static Hashtable fontMetricsHash = new Hashtable();
  private static Stroke[] LineStrokeArray = new Stroke[15];
  private static final MediaTracker mediaTracker = new MediaTracker(new JLabel());

  public static void draw(Graphics paramGraphics, Shape paramShape)
  {
    draw(paramGraphics, paramShape, 1);
  }

  public static void draw(Graphics paramGraphics, Shape paramShape, int paramInt)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    BasicStroke localBasicStroke = (BasicStroke)getStroke(paramInt);
    if ((paramShape instanceof RoundRectangle2D) && (getLineStyleSize(paramInt) == 1))
      localBasicStroke = new BasicStroke(0.2F, localBasicStroke.getEndCap(), localBasicStroke.getLineJoin(), localBasicStroke.getMiterLimit(), localBasicStroke.getDashArray(), localBasicStroke.getDashPhase());
    setStroke(localGraphics2D, localBasicStroke);
    localGraphics2D.draw(paramShape);
  }

  public static void drawLine(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4)
  {
    drawLine(paramGraphics, paramDouble1, paramDouble2, paramDouble3, paramDouble4, 1);
  }

  public static void drawLine(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, int paramInt)
  {
    double d1;
    double d2;
    int i;
    int j;
    int k;
    if (paramInt == 0)
      return;
    if (paramInt == 6)
    {
      d1 = paramDouble3 - paramDouble1;
      d2 = paramDouble4 - paramDouble2;
      i = (int)Math.sqrt(d1 * d1 + d2 * d2);
      if (i == 0)
        break label233;
      j = (int)(-d2 / i);
      k = (int)(d1 / i);
      drawLine(paramGraphics, paramDouble1 - j, paramDouble2 - k, paramDouble3 - j, paramDouble4 - k, 1);
      drawLine(paramGraphics, paramDouble1 + j, paramDouble2 + k, paramDouble3 + j, paramDouble4 + k, 1);
      return;
    }
    if (paramInt == 15)
    {
      d1 = paramDouble3 - paramDouble1;
      d2 = paramDouble4 - paramDouble2;
      i = (int)Math.sqrt(d1 * d1 + d2 * d2);
      if (i != 0)
      {
        j = 1;
        k = (int)(-d2 * j / i);
        int l = (int)(d1 * j / i);
        drawLine(paramGraphics, paramDouble1, paramDouble2, paramDouble3, paramDouble4, 7);
        drawLine(paramGraphics, paramDouble1 + k, paramDouble2 + l, paramDouble3 + k, paramDouble4 + l, 7);
        return;
      }
    }
    label233: tmpLine2D.setLine(paramDouble1, paramDouble2, paramDouble3, paramDouble4);
    draw(paramGraphics, tmpLine2D, paramInt);
  }

  public static void drawRect(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4)
  {
    drawRect(paramGraphics, paramDouble1, paramDouble2, paramDouble3, paramDouble4, 1);
  }

  public static void drawRect(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, int paramInt)
  {
    draw(paramGraphics, new Rectangle2D.Double(paramDouble1, paramDouble2, paramDouble3, paramDouble4), paramInt);
  }

  public static void drawArc(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, double paramDouble6)
  {
    drawArc(paramGraphics, paramDouble1, paramDouble2, paramDouble3, paramDouble4, paramDouble5, paramDouble6, 1);
  }

  public static void drawArc(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, double paramDouble6, int paramInt)
  {
    draw(paramGraphics, new Arc2D.Double(paramDouble1, paramDouble2, paramDouble3, paramDouble4, paramDouble5, paramDouble6, 2), paramInt);
  }

  public static void drawTestGrid(Graphics paramGraphics, Color paramColor, double paramDouble1, double paramDouble2)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    int i = (int)paramDouble2 / 10;
    int j = (int)paramDouble1 / 10;
    localGraphics2D.setPaint(Color.RED);
    for (int k = 0; k < i; ++k)
    {
      drawLine(localGraphics2D, 15.0D, k * 10, paramDouble1 - 15.0D, k * 10);
      drawRotatedString(localGraphics2D, Integer.toString(k * 10), 0.0D, k * 10, 0);
    }
    for (k = 0; k < j; ++k)
    {
      drawLine(localGraphics2D, k * 10, 15.0D, k * 10, paramDouble2 - 15.0D);
      drawRotatedString(localGraphics2D, Integer.toString(k * 10), k * 10, 0.0D, -90);
    }
  }

  public static void fill(Graphics paramGraphics, Shape paramShape)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.fill(paramShape);
  }

  public static void fillRect(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4)
  {
    fill(paramGraphics, new Rectangle2D.Double(paramDouble1, paramDouble2, paramDouble3, paramDouble4));
  }

  public static void fillArc(Graphics paramGraphics, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4, double paramDouble5, double paramDouble6)
  {
    fill(paramGraphics, new Arc2D.Double(paramDouble1, paramDouble2, paramDouble3, paramDouble4, paramDouble5, paramDouble6, 2));
  }

  public static void drawString(Graphics paramGraphics, String paramString, double paramDouble1, double paramDouble2)
  {
    if (StringUtils.isBlank(paramString))
      return;
    if (paramGraphics.getFont() instanceof FRFont)
    {
      FRFont localFRFont = (FRFont)paramGraphics.getFont();
      FontMetrics localFontMetrics = paramGraphics.getFontMetrics(localFRFont);
      int i = localFRFont.getStyle();
      if (localFRFont.isSuperscript())
      {
        paramDouble2 -= localFontMetrics.getAscent() / 3;
        localFRFont = FRFont.getInstance(localFRFont.getName(), i, localFRFont.getSize() * 2 / 3, localFRFont.getForeground(), localFRFont.getUnderline(), localFRFont.isStrikethrough(), localFRFont.isShadow(), localFRFont.isSuperscript(), localFRFont.isSubscript());
        localFontMetrics = paramGraphics.getFontMetrics(localFRFont);
        paramGraphics.setFont(localFRFont);
      }
      else if (localFRFont.isSubscript())
      {
        paramDouble2 += localFontMetrics.getDescent() / 3;
        localFRFont = FRFont.getInstance(localFRFont.getName(), i, localFRFont.getSize() * 2 / 3, localFRFont.getForeground(), localFRFont.getUnderline(), localFRFont.isStrikethrough(), localFRFont.isShadow(), localFRFont.isSuperscript(), localFRFont.isSubscript());
        localFontMetrics = paramGraphics.getFontMetrics(localFRFont);
        paramGraphics.setFont(localFRFont);
      }
      if (localFRFont.isShadow())
      {
        Color localColor = paramGraphics.getColor();
        paramGraphics.setColor(localColor.brighter());
        drawNormalString(paramGraphics, paramString, paramDouble1 + 1.0D, paramDouble2 + 1.0D);
        paramGraphics.setColor(localColor);
      }
      drawNormalString(paramGraphics, paramString, paramDouble1, paramDouble2);
      if (localFRFont.getUnderline() != 0)
      {
        double d1 = paramDouble2 + localFontMetrics.getDescent() + getLineStyleSize(localFRFont.getUnderline());
        drawLine(paramGraphics, paramDouble1, d1, paramDouble1 + localFontMetrics.stringWidth(paramString), d1, localFRFont.getUnderline());
      }
      if (localFRFont.isStrikethrough())
      {
        int j = localFontMetrics.getHeight() + 1;
        double d2 = paramDouble2 - localFontMetrics.getAscent() + j / 2;
        drawLine(paramGraphics, paramDouble1, d2, paramDouble1 + localFontMetrics.stringWidth(paramString), d2, 1);
      }
    }
    else
    {
      drawNormalString(paramGraphics, paramString, paramDouble1, paramDouble2);
    }
  }

  private static void drawNormalString(Graphics paramGraphics, String paramString, double paramDouble1, double paramDouble2)
  {
    ((Graphics2D)paramGraphics).drawString(paramString, (float)paramDouble1, (float)paramDouble2);
  }

  public static void drawRotatedString(Graphics paramGraphics, String paramString, double paramDouble1, double paramDouble2, int paramInt)
  {
    drawRotatedString(paramGraphics, paramString, paramDouble1, paramDouble2, paramInt, 1.0D);
  }

  public static void drawRotatedString(Graphics paramGraphics, String paramString, double paramDouble1, double paramDouble2, int paramInt, double paramDouble3)
  {
    if ((paramString == null) || (paramString.length() == 0))
      return;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Font localFont = localGraphics2D.getFont();
    if (localGraphics2D.getFont() instanceof FRFont)
    {
      localObject1 = (FRFont)localGraphics2D.getFont();
      localObject2 = localGraphics2D.getFontMetrics((Font)localObject1);
      int i = ((FRFont)localObject1).getStyle();
      if (((FRFont)localObject1).isSuperscript())
      {
        paramDouble2 -= ((FontMetrics)localObject2).getAscent() / 3;
        localObject1 = FRFont.getInstance(((FRFont)localObject1).getName(), i, ((FRFont)localObject1).getSize() * 2 / 3, ((FRFont)localObject1).getForeground(), ((FRFont)localObject1).getUnderline(), ((FRFont)localObject1).isStrikethrough(), ((FRFont)localObject1).isShadow(), ((FRFont)localObject1).isSuperscript(), ((FRFont)localObject1).isSubscript());
        localGraphics2D.setFont((Font)localObject1);
      }
      else if (((FRFont)localObject1).isSubscript())
      {
        paramDouble2 += ((FontMetrics)localObject2).getDescent() / 3;
        localObject1 = FRFont.getInstance(((FRFont)localObject1).getName(), i, ((FRFont)localObject1).getSize() * 2 / 3, ((FRFont)localObject1).getForeground(), ((FRFont)localObject1).getUnderline(), ((FRFont)localObject1).isStrikethrough(), ((FRFont)localObject1).isShadow(), ((FRFont)localObject1).isSuperscript(), ((FRFont)localObject1).isSubscript());
        localGraphics2D.setFont((Font)localObject1);
      }
    }
    Object localObject1 = localGraphics2D.getFontMetrics();
    Object localObject2 = localGraphics2D.getFontRenderContext();
    Rectangle2D localRectangle2D = ((FontMetrics)localObject1).getStringBounds(paramString, localGraphics2D);
    LineMetrics localLineMetrics = localFont.getLineMetrics(paramString, (java.awt.font.FontRenderContext)localObject2);
    double d1 = localLineMetrics.getDescent();
    double d2 = localLineMetrics.getLeading();
    double[] arrayOfDouble1 = new double[2];
    arrayOfDouble1[0] = (-localRectangle2D.getWidth() / 2.0D);
    arrayOfDouble1[1] = (-d1 - d2 + localRectangle2D.getHeight() / 2.0D);
    double[] arrayOfDouble2 = new double[2];
    arrayOfDouble2[0] = (localRectangle2D.getWidth() / 2.0D);
    arrayOfDouble2[1] = (d1 + d2 - localRectangle2D.getHeight() / 2.0D);
    AffineTransform localAffineTransform1 = localGraphics2D.getTransform();
    AffineTransform localAffineTransform2 = AffineTransform.getRotateInstance(Math.toRadians(paramInt), paramDouble1 + arrayOfDouble1[0] + arrayOfDouble2[0], paramDouble2 + arrayOfDouble1[1] + arrayOfDouble2[1]);
    localGraphics2D.transform(localAffineTransform2);
    TextLayout localTextLayout = new TextLayout(paramString, localGraphics2D.getFont(), localGraphics2D.getFontRenderContext());
    if (localGraphics2D.getFont() instanceof FRFont)
    {
      FRFont localFRFont = (FRFont)localGraphics2D.getFont();
      float f1 = (float)(paramDouble1 + arrayOfDouble1[0]);
      float f2 = (float)(paramDouble2 + arrayOfDouble1[1]);
      if (localFRFont.isShadow())
      {
        Color localColor = localGraphics2D.getColor();
        localGraphics2D.setColor(localColor.brighter());
        localGraphics2D.scale(paramDouble3, paramDouble3);
        localTextLayout.draw(localGraphics2D, (float)((f1 + 1.0F) / paramDouble3), (float)((f2 + 1.0F) / paramDouble3));
        localGraphics2D.scale(1.0D / paramDouble3, 1.0D / paramDouble3);
        localGraphics2D.setColor(localColor);
      }
      int j = ((FontMetrics)localObject1).stringWidth(paramString);
      drawLine(localGraphics2D, f1, f2 + ((FontMetrics)localObject1).getDescent(), f1 + j, f2 + ((FontMetrics)localObject1).getDescent(), localFRFont.getUnderline());
      if (localFRFont.isStrikethrough())
        drawLine(localGraphics2D, f1, f2 + ((FontMetrics)localObject1).getDescent() - ((FontMetrics)localObject1).getAscent() / 2 - ((FontMetrics)localObject1).getDescent() / 2, f1 + j, f2 + ((FontMetrics)localObject1).getDescent() - ((FontMetrics)localObject1).getAscent() / 2 - ((FontMetrics)localObject1).getDescent() / 2);
      localGraphics2D.scale(paramDouble3, paramDouble3);
      localTextLayout.draw(localGraphics2D, (float)(f1 / paramDouble3), (float)(f2 / paramDouble3));
      localGraphics2D.scale(1.0D / paramDouble3, 1.0D / paramDouble3);
    }
    else
    {
      localGraphics2D.scale(paramDouble3, paramDouble3);
      localTextLayout.draw(localGraphics2D, (float)((paramDouble1 + arrayOfDouble1[0]) / paramDouble3), (float)((paramDouble2 + arrayOfDouble1[1]) / paramDouble3));
      localGraphics2D.scale(1.0D / paramDouble3, 1.0D / paramDouble3);
    }
    localGraphics2D.setTransform(localAffineTransform1);
  }

  public static void drawAutoWrapString(Graphics2D paramGraphics2D, String paramString, double paramDouble1, double paramDouble2, double paramDouble3)
  {
    drawAutoWrapString(paramGraphics2D, paramString, paramDouble1, paramDouble2, paramDouble3, 0.0D);
  }

  public static void drawAutoWrapString(Graphics2D paramGraphics2D, String paramString, double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4)
  {
    int i = paramString.length();
    StringTokenizer localStringTokenizer = new StringTokenizer(paramString, "\n");
    for (int j = 0; j < i; ++j)
    {
      k = paramString.charAt(j);
      if (k == 13)
      {
        if ((j < i - 1) && (paramString.charAt(j + 1) == '\n'))
        {
          localStringTokenizer = new StringTokenizer(paramString, "\r\n");
          break;
        }
        localStringTokenizer = new StringTokenizer(paramString, "\r");
        break;
      }
      if (k == 10)
        break;
    }
    j = 0;
    int k = localStringTokenizer.countTokens();
    String[] arrayOfString = new String[k];
    while (localStringTokenizer.hasMoreElements())
    {
      localObject = localStringTokenizer.nextToken();
      if (localObject == null)
        localObject = " ";
      arrayOfString[(j++)] = localObject;
    }
    Object localObject = new Vector();
    for (int l = 0; l < arrayOfString.length; ++l)
    {
      AttributedString localAttributedString = new AttributedString(arrayOfString[l], paramGraphics2D.getFont().getAttributes());
      LineBreakMeasurer localLineBreakMeasurer = new LineBreakMeasurer(localAttributedString.getIterator(), paramGraphics2D.getFontRenderContext());
      while (localLineBreakMeasurer.getPosition() < arrayOfString[l].length())
        ((Vector)localObject).add(localLineBreakMeasurer.nextLayout((float)paramDouble3));
    }
    double d1 = paramDouble1;
    double d2 = paramDouble2;
    AffineTransform localAffineTransform1 = null;
    if (paramDouble4 != 0.0D)
    {
      localAffineTransform1 = new AffineTransform();
      localAffineTransform1.setToRotation(-Math.toRadians(paramDouble4));
    }
    for (int i1 = 0; i1 < ((Vector)localObject).size(); ++i1)
    {
      TextLayout localTextLayout = (TextLayout)((Vector)localObject).elementAt(i1);
      d1 = (localTextLayout.isLeftToRight()) ? paramDouble1 : paramDouble3 - localTextLayout.getAdvance();
      double[] arrayOfDouble = { 0.0D, localTextLayout.getAscent(), 0.0D, localTextLayout.getDescent(), 0.0D, localTextLayout.getLeading() };
      if (localAffineTransform1 != null)
        localAffineTransform1.transform(arrayOfDouble, 0, arrayOfDouble, 0, 3);
      d2 += arrayOfDouble[1];
      AffineTransform localAffineTransform2 = paramGraphics2D.getTransform();
      paramGraphics2D.translate(d1, d2);
      if (localAffineTransform1 != null)
        paramGraphics2D.transform(localAffineTransform1);
      else
        paramGraphics2D.transform(new AffineTransform());
      localTextLayout.draw(paramGraphics2D, 0.0F, 0.0F);
      paramGraphics2D.setTransform(localAffineTransform2);
      d2 += arrayOfDouble[3] + arrayOfDouble[5];
    }
  }

  public static void waitForImage(Image paramImage)
  {
    mediaTracker.addImage(paramImage, 0);
    try
    {
      mediaTracker.waitForAll();
    }
    catch (Exception localException)
    {
    }
    mediaTracker.removeImage(paramImage);
  }

  public static BufferedImage createBufferedImageFromImage(Image paramImage)
  {
    if (paramImage instanceof BufferedImage)
      return ((BufferedImage)paramImage);
    waitForImage(paramImage);
    int i = paramImage.getWidth(null);
    int j = paramImage.getHeight(null);
    BufferedImage localBufferedImage = createBufferedImage(i, j, 2);
    Graphics2D localGraphics2D = localBufferedImage.createGraphics();
    localGraphics2D.drawImage(paramImage, 0, 0, null);
    return localBufferedImage;
  }

  public static void setStroke(Graphics2D paramGraphics2D, Stroke paramStroke)
  {
    Stroke localStroke = paramGraphics2D.getStroke();
    if (paramStroke.hashCode() != localStroke.hashCode())
      paramGraphics2D.setStroke(paramStroke);
  }

  public static Stroke getStroke(int paramInt)
  {
    Object localObject = null;
    if (paramInt < LineStrokeArray.length)
    {
      localObject = LineStrokeArray[paramInt];
      if (localObject == null)
        break label52;
      return localObject;
    }
    Stroke[] arrayOfStroke = LineStrokeArray;
    LineStrokeArray = new Stroke[Math.max(10, arrayOfStroke.length * 2)];
    System.arraycopy(arrayOfStroke, 0, LineStrokeArray, 0, arrayOfStroke.length);
    label52: int i = 0;
    int j = 0;
    switch (paramInt)
    {
    case 1:
      localObject = new BasicStroke(1.0F, i, j);
      break;
    case 2:
      localObject = new BasicStroke(2.0F, i, j);
      break;
    case 3:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 4.0F, 2.0F }, 0.0F);
      break;
    case 4:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 2.0F }, 0.0F);
      break;
    case 14:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 4.0F }, 0.0F);
      break;
    case 5:
      localObject = new BasicStroke(3.0F, i, j);
      break;
    case 6:
      break;
    case 7:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 1.0F }, 0.0F);
      break;
    case 8:
      localObject = new BasicStroke(2.0F, i, j, 10.0F, new float[] { 8.0F, 2.0F }, 0.0F);
      break;
    case 9:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 8.0F, 4.0F, 2.0F, 4.0F }, 0.0F);
      break;
    case 10:
      localObject = new BasicStroke(2.0F, i, j, 10.0F, new float[] { 8.0F, 4.0F, 2.0F, 4.0F }, 0.0F);
      break;
    case 11:
      localObject = new BasicStroke(1.0F, i, j, 10.0F, new float[] { 8.0F, 4.0F, 2.0F, 4.0F, 2.0F, 4.0F }, 0.0F);
      break;
    case 12:
      localObject = new BasicStroke(2.0F, i, j, 10.0F, new float[] { 8.0F, 4.0F, 2.0F, 4.0F, 2.0F, 4.0F }, 0.0F);
      break;
    case 13:
      localObject = new BasicStroke(2.0F, i, j, 10.0F, new float[] { 8.0F, 4.0F, 2.0F, 4.0F }, 0.0F);
    case 15:
    }
    if (localObject == null)
      localObject = new BasicStroke(1.0F, i, j);
    LineStrokeArray[paramInt] = localObject;
    return ((Stroke)localObject);
  }

  public static int getLineStyleSize(int paramInt)
  {
    if (paramInt == 0)
      return 0;
    if ((paramInt == 2) || (paramInt == 6) || (paramInt == 8) || (paramInt == 10) || (paramInt == 12) || (paramInt == 13))
      return 2;
    if (paramInt == 5)
      return 3;
    return 1;
  }

  public static double stringWidth(String paramString, Font paramFont, java.awt.font.FontRenderContext paramFontRenderContext)
  {
    if ((paramString == null) || (paramString.length() <= 0))
      return 0.0D;
    double d = paramFont.getStringBounds(paramString, paramFontRenderContext).getWidth();
    if (paramFont instanceof FRFont)
    {
      FRFont localFRFont = (FRFont)paramFont;
      if ((localFRFont.isSuperscript()) || (localFRFont.isSubscript()))
        d = d * 2.0D / 3.0D;
    }
    return d;
  }

  public static Dimension2D stringDimension(String paramString, Font paramFont, int paramInt, java.awt.font.FontRenderContext paramFontRenderContext)
  {
    Rectangle2D localRectangle2D = paramFont.getStringBounds(paramString, paramFontRenderContext);
    double d1 = localRectangle2D.getWidth();
    double d2 = Math.toRadians(paramInt);
    return new DoubleDimension2D(d1 * Math.abs(Math.cos(d2)) + localRectangle2D.getHeight() * Math.abs(Math.sin(d2)), d1 * Math.abs(Math.sin(d2)) + localRectangle2D.getHeight() * Math.abs(Math.cos(d2)));
  }

  public static BufferedImage createBufferedImage(int paramInt1, int paramInt2)
  {
    return createBufferedImage(paramInt1, paramInt2, 2);
  }

  public static BufferedImage createBufferedImage(int paramInt1, int paramInt2, int paramInt3)
  {
    if (paramInt1 <= 0)
      paramInt1 = 1;
    if (paramInt2 <= 0)
      paramInt2 = 1;
    return new BufferedImage(paramInt1, paramInt2, paramInt3);
  }

  public static FontMetrics getFontMetrics(Font paramFont)
  {
    if (paramFont == oldFont)
      return oldFontMetrics;
    if (paramFont == null)
    {
      localObject = FRContext.getDefaultValues();
      paramFont = ((DefaultValues)localObject).getFRFont();
    }
    Object localObject = (FontMetrics)fontMetricsHash.get(paramFont);
    if (localObject == null)
    {
      localObject = BaseCoreConstants.getDefaultToolkit().getFontMetrics(paramFont);
      fontMetricsHash.put(paramFont, localObject);
    }
    oldFont = paramFont;
    oldFontMetrics = (FontMetrics)localObject;
    return ((FontMetrics)localObject);
  }

  public static void paintImage(Graphics paramGraphics, int paramInt1, int paramInt2, Image paramImage, Style paramStyle, int paramInt3, int paramInt4, int paramInt5)
  {
    int i;
    int j;
    if (paramImage == null)
      return;
    waitForImage(paramImage);
    if (paramInt4 == -1)
      i = paramImage.getWidth(null);
    else
      i = paramInt4;
    if (paramInt5 == -1)
      j = paramImage.getHeight(null);
    else
      j = paramInt5;
    if (paramInt3 == 0)
    {
      if ((i < 0) || (j < 0))
        return;
      int k = 0;
      while (true)
      {
        if (k >= paramInt1)
          return;
        int i1 = 0;
        while (i1 < paramInt2)
        {
          paramGraphics.drawImage(paramImage, k, i1, i, j, null);
          i1 += j;
        }
        k += i;
      }
    }
    if (paramInt3 == 1)
    {
      paramGraphics.drawImage(paramImage, (paramInt1 - i) / 2, (paramInt2 - j) / 2, i, j, null);
    }
    else if (paramInt3 == 2)
    {
      paramGraphics.drawImage(paramImage, 0, 0, paramInt1, paramInt2, null);
    }
    else if (paramInt3 == 3)
    {
      int l;
      int i2;
      if (paramStyle == null)
      {
        l = 0;
        i2 = 0;
      }
      else
      {
        if (paramStyle.getHorizontalAlignment() == 4)
          l = paramInt1 - i;
        else if (paramStyle.getHorizontalAlignment() == 0)
          l = (paramInt1 - i) / 2;
        else
          l = 0;
        if (paramStyle.getVerticalAlignment() == 3)
          i2 = paramInt2 - j;
        else if (paramStyle.getVerticalAlignment() == 0)
          i2 = (paramInt2 - j) / 2;
        else
          i2 = 0;
      }
      if ((i > 0) && (j > 0))
        paramGraphics.drawImage(paramImage, l, i2, i, j, null);
    }
  }

  public static void paintImage2(Graphics paramGraphics, int paramInt1, int paramInt2, Image paramImage, Style paramStyle, int paramInt3, int paramInt4, int paramInt5, int paramInt6, int paramInt7)
  {
    int i;
    int j;
    int k;
    int l;
    int i1;
    int i2;
    if (paramImage == null)
      return;
    waitForImage(paramImage);
    if (paramInt4 == -1)
      i = paramImage.getWidth(null);
    else
      i = paramInt4;
    if (paramInt5 == -1)
      j = paramImage.getHeight(null);
    else
      j = paramInt5;
    if ((i < 0) || (j < 0))
      return;
    if (paramInt3 == 0)
    {
      k = -paramInt6;
      l = -paramInt6;
      i1 = -paramInt6;
      while (true)
      {
        if (i1 >= paramInt1)
          return;
        if ((i1 + paramInt6) / paramInt1 > (k + paramInt6) / paramInt1)
          i1 = ((k + paramInt6) / paramInt1 + 1) * paramInt1 - paramInt6;
        i2 = -paramInt7;
        while (i2 < paramInt2)
        {
          if ((i2 + paramInt7) / paramInt2 > (l + paramInt7) / paramInt2)
            i2 = ((l + paramInt7) / paramInt2 + 1) * paramInt2 - paramInt7;
          paramGraphics.drawImage(paramImage, i1, i2, i, j, null);
          k = i1;
          l = i2;
          i2 += j;
        }
        i1 += i;
      }
    }
    if (paramInt3 == 1)
    {
      k = ((paramInt1 - i) / 2 - paramInt6) % paramInt1;
      while (true)
      {
        if (k >= paramInt1)
          return;
        l = ((paramInt2 - j) / 2 - paramInt7) % paramInt2;
        while (l < paramInt2)
        {
          paramGraphics.drawImage(paramImage, Math.max(k, k - (paramInt1 - i) / 2), Math.max(l, l - (paramInt2 - j) / 2), (k > k - (paramInt1 - i) / 2) ? i : paramInt1, (l > l - (paramInt2 - j) / 2) ? j : paramInt2, null);
          l += paramInt2;
        }
        k += paramInt1;
      }
    }
    if (paramInt3 == 2)
    {
      k = -paramInt6 % paramInt1;
      while (true)
      {
        if (k >= paramInt1)
          return;
        l = -paramInt7 % paramInt2;
        while (l < paramInt2)
        {
          paramGraphics.drawImage(paramImage, k, l, paramInt1, paramInt2, null);
          l += paramInt2;
        }
        k += paramInt1;
      }
    }
    if (paramInt3 == 3)
    {
      if (paramStyle == null)
      {
        k = -paramInt6;
        l = -paramInt7;
      }
      else
      {
        if (paramStyle.getHorizontalAlignment() == 4)
          k = paramInt1 - i - paramInt6;
        else if (paramStyle.getHorizontalAlignment() == 0)
          k = (paramInt1 - i) / 2 - paramInt6;
        else
          k = -paramInt6;
        if (paramStyle.getVerticalAlignment() == 3)
          l = paramInt2 - j - paramInt7;
        else if (paramStyle.getVerticalAlignment() == 0)
          l = (paramInt2 - j) / 2 - paramInt7;
        else
          l = -paramInt7;
      }
      if ((i > 0) && (j > 0))
      {
        i1 = k % paramInt1;
        while (i1 < paramInt1)
        {
          i2 = l % paramInt2;
          while (i2 < paramInt2)
          {
            paramGraphics.drawImage(paramImage, i1, i2, i, j, null);
            i2 += paramInt2;
          }
          i1 += paramInt1;
        }
      }
    }
  }
}